<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
	<meta charset="utf-8" />
		<title>内贸基础运价表</title>		
		
			<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/ext-all-debug.js"></script>
<script type="text/javascript" src="static/js/jquery-1.7.2.js" />
			<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/locale/ext-lang-zh_CN.js"></script>
			<link rel="stylesheet" href="plugins/websocketInstantMsg/ext4/resources/css/ext-all.css" />
			
			
</head>
<body>
<div id="payment"></div>
<div id="payment1"></div>
<div id="payment2"></div>
</body>
<script type="text/javascript">
Ext.onReady(function(){
	Ext.QuickTips.init();
	var store = Ext.create('Ext.data.Store', {
		fields: ["ID","GOODS_NAME","GOODS_CATEGORY_NAME","ORGIN_PORT_START_MILEAGE","ORGIN_PORT_END_MILEAGE",
		         "DOMESTIC_TRADE_PRICE","FOREIGN_TRADE_PRICE","EMPTY_CONTAINER_PRICE","DEST_PORT_BEGIN_MILEAGE",
		         "DEST_PORT_END_MILEAGE","BOX_TYPE","REMARK","ENABLE","SPELL_CODE","START_PRICE_EXP_DATE","END_PRICE_EXP_DATE"],
		pageSize: 10,  //页容量5条数据
		//是否在服务端排序 （true的话，在客户端就不能排序）
		remoteSort: false,
		remoteFilter: true,
		proxy: {
			type: 'ajax',
			url: '<%=basePath%>internalTradeBase/internalTradeBaseInfo',
			reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
				type: 'json', //返回数据类型为json格式
				root: 'result.list',  //数据
				totalProperty: 'result.total' //数据总条数
			}
		},
		sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
		autoLoad: true
	});
	var goodsType = Ext.create('Ext.data.Store', {
		fields: ['id', 'name'],
		data : [
			{"id":"", "name":"请选择"},
			{"id":"0", "name":"活动物"},
			{"id":"1", "name":"冷藏品"},
			{"id":"2", "name":"普通货物"},
			{"id":"3", "name":"食品货物"},
			{"id":"4", "name":"危险冷藏品"},
			{"id":"5", "name":"危险品"}
		]
	});
	var enable = Ext.create('Ext.data.Store', {
		fields: ['id', 'name'],
		data : [
			{"id":"", "name":"请选择"},
			{"id":"1", "name":"是"},
			{"id":"0", "name":"否"}
		]
	});
	
	  var c2 = Ext.create('Ext.container.Container', {
			layout: 'column',
//			defaults: { labelAlign: 'left', labelWidth: 80 },
			items: [
				{id:"ID",xtype: 'textfield',labelWidth: 90, name: 'ID', columnWidth:  1/5,padding: '5px',hidden:true},
				{id:"GOODS_NAME",xtype: 'textfield',labelWidth: 60, name: 'GOODS_NAME', columnWidth:  1/5,padding: '5px', fieldLabel: '货物名称'},
				{id:"GOODS_CATEGORY_NAME",xtype: 'combo',labelWidth: 60, name: 'GOODS_CATEGORY_NAME',columnWidth: 1/5,padding: '5px',store:goodsType,displayField:'name',fieldLabel: '货物类别'},
				{id:"ORGIN_PORT_START_MILEAGE",xtype: 'textfield',regex: /^\d+$/,regexText: '请输入数字', labelWidth: 90,name: 'ORGIN_PORT_START_MILEAGE',columnWidth: 1/5,padding: '5px',fieldLabel: '起点港开始里程'},
				{id:"ORGIN_PORT_END_MILEAGE",xtype: 'textfield',regex: /^\d+$/,regexText: '请输入数字',labelWidth: 90,name: 'ORGIN_PORT_END_MILEAGE',columnWidth: 1/5,padding: '5px',fieldLabel: '起点港结束里程'},
				{id:"DOMESTIC_TRADE_PRICE",xtype: 'textfield',regex:/^\d+(\.\d{1,2})?$/,regexText: '请输入小数或数字',labelWidth: 60, name: 'DOMESTIC_TRADE_PRICE', columnWidth:  1/5,padding: '5px', fieldLabel: '内贸价格'},
				{id:"FOREIGN_TRADE_PRICE",xtype: 'textfield',regex: /^\d+(\.\d{1,2})?$/,regexText: '请输入小数或数字',labelWidth: 60, name: 'FOREIGN_TRADE_PRICE',columnWidth: 1/5,padding: '5px',fieldLabel: '外贸价格'},
				{id:"EMPTY_CONTAINER_PRICE",xtype: 'textfield', regex:/^\d+(\.\d{1,2})?$/,regexText: '请输入小数或数字',labelWidth: 60,name: 'EMPTY_CONTAINER_PRICE',columnWidth: 1/5,padding: '5px',fieldLabel: '空箱价格'},
				{id:"DEST_PORT_BEGIN_MILEAGE",xtype: 'textfield',regex: /^\d+$/,regexText: '请输入数字',labelWidth: 90, name: 'DEST_PORT_BEGIN_MILEAGE', columnWidth:  1/5,padding: '5px', fieldLabel: '终点港开始里程'},
				{id:"DEST_PORT_END_MILEAGE",xtype: 'textfield',regex: /^\d+$/,regexText: '请输入数字',labelWidth: 90, name: 'DEST_PORT_END_MILEAGE',columnWidth: 1/5,padding: '5px',fieldLabel: '终点港结束里程'},
				{id:"BOX_TYPE",xtype: 'textfield', labelWidth: 50,name: 'BOX_TYPE',columnWidth: 1/5,padding: '5px',fieldLabel: '箱型'},
				{id:"REMARK",xtype: 'textfield',labelWidth: 50, name: 'REMARK', columnWidth:  1/5,padding: '5px', fieldLabel: '备注'},
				{id:"ENABLE",labelWidth: 60, name: 'ENABLE',xtype: 'combo',columnWidth: 1/5,store:enable,displayField:'name',padding: '5px',fieldLabel: '是否可用'},
				{id:"SPELL_CODE",xtype: 'textfield', labelWidth: 60,name: 'SPELL_CODE',columnWidth: 1/5,padding: '5px',fieldLabel: '检索码'},
				{id:"START_PRICE_EXP_DATE",xtype: 'datefield',labelWidth: 80, name: 'START_PRICE_EXP_DATE', columnWidth:  1/5,padding: '5px', fieldLabel: '价格有效期起'},
				{id:"END_PRICE_EXP_DATE",xtype: 'datefield',labelWidth: 80, name: 'END_PRICE_EXP_DATE',columnWidth: 1/5,padding: '5px',fieldLabel: '价格有效期止'},

			]
		});
	  
	  var bs2 = Ext.create('Ext.container.Container', {
			layout: 'column',
			items: [
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,   padding: '10px'},
				{layout : 'column',baseCls : 'my-panel-no-border',columnWidth: 2/5,  padding: '10px',  items: [
					
				      	{ style: {marginRight:'10px'}, xtype: "button",minWidth:70,icon:'<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "保存",handler: function(){
				      		var form = Ext.getCmp('selForm').getForm();
				      		if(form.isValid()){
		       		            	form.submit({
		       		            		params:{
		       		            		
		       		            		
		       		            			
		       		            		},
		       		            		waitTitle : '请稍后...',  
		       		            		waitMsg : '正在保存信息,请稍后...',  
		       		            		url:'<%=basePath%>internalTradeBase/saveInternalTradeBaseInfo',
				          				success:function(form,action){
				          					Ext.Msg.alert("提示","保存成功");
				          					store.load();
				          					win.close();
				          					
				          				},

				          			});
		       		            }else{
		       		          		Ext.Msg.alert("失败","请确认信息是否输入正确");
		       		            }
// 				      		 var SUPPLIER = Ext.getCmp('startDate1').getValue();
// 					      		var ACCOUNT_BANK = Ext.getCmp('startDate2').getValue();
// 					      		var ACCOUNT_BANK_NUMBER = Ext.getCmp('startDate3').getValue();
// 					      		var CURRENCY = Ext.getCmp('startDate4').getValue();
// 					      		Ext.Ajax.request({
<%-- 					      			 url: '<%=basePath%>paymentUnit/saveOrUpdatePaymentUnitInfo', --%>
// 					      			 params:{SUPPLIER : SUPPLIER, ACCOUNT_BANK:ACCOUNT_BANK,ACCOUNT_BANK_NUMBER:ACCOUNT_BANK_NUMBER,CURRENCY:CURRENCY},
// 					      			 method: 'POST',
// 					        			success: function () {
// 											Ext.getCmp("startDate1").setValue(null); 
// 											Ext.getCmp("startDate2").setValue(null); 
// 											Ext.getCmp("startDate3").setValue(null); 
// 											Ext.getCmp("startDate4").setValue(null);
// 											store.load();
// 					        			}
// 					      		});
				      	},
				      	},{ style: {marginRight:'10px'}, xtype: "button",minWidth:70,icon:'<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/plugin.gif', text: "重置",handler: function(){
				      		Ext.getCmp("ID").setValue(null); 
				     		Ext.getCmp("GOODS_NAME").setValue(null); 
							Ext.getCmp("GOODS_CATEGORY_NAME").setValue(null); 
							Ext.getCmp("ORGIN_PORT_START_MILEAGE").setValue(null); 
							Ext.getCmp("ORGIN_PORT_END_MILEAGE").setValue(null);
							Ext.getCmp("DOMESTIC_TRADE_PRICE").setValue(null);
							Ext.getCmp("FOREIGN_TRADE_PRICE").setValue(null); 
							Ext.getCmp("EMPTY_CONTAINER_PRICE").setValue(null); 
							Ext.getCmp("DEST_PORT_BEGIN_MILEAGE").setValue(null); 
							Ext.getCmp("DEST_PORT_END_MILEAGE").setValue(null);
							Ext.getCmp("BOX_TYPE").setValue(null);
							Ext.getCmp("REMARK").setValue(null); 
							Ext.getCmp("ENABLE").setValue(null); 
							Ext.getCmp("SPELL_CODE").setValue(null); 
							Ext.getCmp("START_PRICE_EXP_DATE").setValue(null);
							Ext.getCmp("END_PRICE_EXP_DATE").setValue(null);
				      	},
				      	},


				],},
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,  padding: '10px'}
			]
		});
	  var c = Ext.create('Ext.container.Container', {
			layout: 'column',
//			defaults: { labelAlign: 'left', labelWidth: 80 },
			items: [
				
				{id:"startDate1",xtype: 'textfield',labelWidth: 60, name: 'startDate1', columnWidth:  1/5,padding: '5px', fieldLabel: '检索码'},
				{id:"startDate2",xtype: 'textfield',labelWidth: 70, name: 'startDate2',columnWidth: 1/5,padding: '5px',fieldLabel: '货物名称'},
				{id:"startDate3",xtype: 'textfield', labelWidth: 50,name: 'startDate3',columnWidth: 1/5,padding: '5px',fieldLabel: '箱型'},
			]
		});
	  var bs = Ext.create('Ext.container.Container', {
			layout: 'column',
			items: [
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,   padding: '10px'},
				{layout : 'column',baseCls : 'my-panel-no-border',columnWidth: 2/5,  padding: '10px',  items: [
					{ style: {marginRight:'10px'}, xtype: "button",minWidth:70,icon:'<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/table_refresh.png', text: "查询",handler: function(){
			      		 var SPELL_CODE = Ext.getCmp('startDate1').getValue();
				      		var GOODS_NAME = Ext.getCmp('startDate2').getValue();
				      		var BOX_TYPE = Ext.getCmp('startDate3').getValue();
					var store = Ext.getCmp('grid').getStore();
					store.on('beforeload', function(store,options) {  
				            var new_params = {  
				            		GOODS_NAME : encodeURI(GOODS_NAME), SPELL_CODE:encodeURI(SPELL_CODE),BOX_TYPE:encodeURI(BOX_TYPE)
				            };  
					//这里apply一下实现新的proxy  
				            Ext.apply(store.proxy.extraParams,new_params);  
				        });  
					//对store重新载入  
				        store.load();  


							
				      	 } },
				],},
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,  padding: '10px'}
			]
		});
	var grid = Ext.create('Ext.grid.Panel', {
		renderTo:'payment2',
		store: store,
		id:'grid',
		forceFit: true,
		height: 320,
		title:'付款单位',
		stripeRows:true,
		columnLines: true,
		selModel:Ext.create('Ext.selection.CheckboxModel',{checkOnly:false}),
		columns: [
			{text: 'ID', dataIndex: 'ID',hidden:true},
			{text: '货物名称', dataIndex: 'GOODS_NAME'},
			{text: '货物类别', dataIndex: 'GOODS_CATEGORY_NAME'},
			{text: '起点开始里程', dataIndex: 'ORGIN_PORT_START_MILEAGE'},
			{text: '起点结束里程', dataIndex: 'ORGIN_PORT_END_MILEAGE', align: 'left'},
			{text: '内贸价格', dataIndex: 'DOMESTIC_TRADE_PRICE'},
			{text: '外贸价格', dataIndex: 'FOREIGN_TRADE_PRICE'},
			{text: '空箱价格', dataIndex: 'EMPTY_CONTAINER_PRICE'},
			{text: '终点港开始里程', dataIndex: 'DEST_PORT_BEGIN_MILEAGE', align: 'left'},
			{text: '终点港结束里程', dataIndex: 'DEST_PORT_END_MILEAGE'},
			{text: '箱型', dataIndex: 'BOX_TYPE'},
			{text: '是否可用', dataIndex: 'ENABLE'},
			{text: '检索码', dataIndex: 'SPELL_CODE', align: 'left'},
			{text: '备注', dataIndex: 'REMARK', align: 'left'},
			{text: '价格有效期起', dataIndex: 'START_PRICE_EXP_DATE', align: 'left'},
			{text: '价格有效期止', dataIndex: 'END_PRICE_EXP_DATE', align: 'left'},
		],
		bbar: [{
			xtype: 'pagingtoolbar',
			store: store,
			displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
			emptyMsg: "没有数据",
			beforePageText: "当前页",
			afterPageText: "共{0}页",
			displayInfo: true
		}],

		tbar: [
			{text: '修改', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/cog_edit.png', handler: function (){
				 var records = grid.getSelectionModel().getSelection();
			   	 if(records.length==0){
			     			Ext.Msg.alert("提示","请选择一条记录");return;
			     		}
			     		if(records.length>1){
			     			Ext.Msg.alert("提示","只能编辑一条记录");return;
			     		}
			     		
			     		Ext.getCmp("ID").setValue(records[0].data.ID); 
			     		Ext.getCmp("GOODS_NAME").setValue(records[0].data.GOODS_NAME); 
						Ext.getCmp("GOODS_CATEGORY_NAME").setValue(records[0].data.GOODS_CATEGORY_NAME); 
						Ext.getCmp("ORGIN_PORT_START_MILEAGE").setValue(records[0].data.ORGIN_PORT_START_MILEAGE); 
						Ext.getCmp("ORGIN_PORT_END_MILEAGE").setValue(records[0].data.ORGIN_PORT_END_MILEAGE);
						Ext.getCmp("DOMESTIC_TRADE_PRICE").setValue(records[0].data.DOMESTIC_TRADE_PRICE);
						Ext.getCmp("FOREIGN_TRADE_PRICE").setValue(records[0].data.FOREIGN_TRADE_PRICE); 
						Ext.getCmp("EMPTY_CONTAINER_PRICE").setValue(records[0].data.EMPTY_CONTAINER_PRICE); 
						Ext.getCmp("DEST_PORT_BEGIN_MILEAGE").setValue(records[0].data.DEST_PORT_BEGIN_MILEAGE); 
						Ext.getCmp("DEST_PORT_END_MILEAGE").setValue(records[0].data.DEST_PORT_END_MILEAGE);
						Ext.getCmp("BOX_TYPE").setValue(records[0].data.BOX_TYPE);
						Ext.getCmp("REMARK").setValue(records[0].data.REMARK); 
						Ext.getCmp("ENABLE").setValue(records[0].data.ENABLE); 
						Ext.getCmp("SPELL_CODE").setValue(records[0].data.SPELL_CODE); 
						Ext.getCmp("START_PRICE_EXP_DATE").setValue(records[0].data.START_PRICE_EXP_DATE);
						Ext.getCmp("END_PRICE_EXP_DATE").setValue(records[0].data.END_PRICE_EXP_DATE);
			} },
			{text: '删除', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/cross.gif', handler: function (){
				var records = grid.getSelectionModel().getSelection();
       			if(records.length==0){
       				Ext.Msg.alert("提示","请选中需要删除的记录");return;
       			}
       			var arr = [];
       			Ext.each(records,function(item){
       				obj = {
       						id:item.data.ID
       				};
       				arr.push(obj);
       			});
       			var array = JSON.stringify(arr);
       			Ext.Msg.confirm("提示","确定删除数据?",function(btn){
	       				
	       					Ext.Ajax.request({
	       						url:'<%=basePath%>internalTradeBase/deleteInfo',
	       						params:{
	       							array:array
	       						},
	       						timeout:5000,
	       						success:function(response){
	       							store.load();
	       							Ext.Msg.alert("成功","删除成功!");
	       						},
	       						failure:function(response){
	       							Ext.Msg.alert("错误","请求异常!");
	       						}
	       					});
	       				
	       			});
			} },{text: '导入', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/control_rewind.png', 
				handler:
				 toImport
			
			},
			]
	});
	  var selForm = Ext.create('Ext.form.Panel', {
			title:'内贸基础运价',
			id:'selForm',
			name: 'selForm',
			renderTo:'payment',
			width:'100%',
//			collapsed :true,
			height:200,
//			collapsible:true,
			bodyStyle: {
				padding: '5px',
				border: 1
			},
			fieldDefaults: {
				labelAlign: 'left'
			},
			items: [c2,bs2]
		});
	  var selForm1 = Ext.create('Ext.form.Panel', {
// 			title:'内贸基础运价',
			id:'selForm1',
			name: 'selForm1',
			renderTo:'payment1',
			width:'100%',
//			collapsed :true,
			height:100,
//			collapsible:true,
			bodyStyle: {
				padding: '5px',
				border: 1
			},
			fieldDefaults: {
				labelAlign: 'left'
			},
			items: [c,bs]
		});
	  var uploadForm = Ext.create('Ext.form.Panel', {
		    items: [
		        {
		            xtype: 'filefield',
		            fieldLabel: '文件上传',
		            name:"file",
		            labelWidth: 80,
		            msgTarget: 'side',
		            allowBlank: false,
		            emptyText: "请选择上传文件",
		            blankText:"请选择上传文件",
		            margin: '10,10,10,10',
		            anchor: '100%',
		            buttonText:'选择文件'
		        }],
		    buttonAlign:'center'

		});


		var impWin = Ext.create('Ext.window.Window', {
		    title: '支付单位',
		    modal : true,
		    items: [uploadForm],
		    closeAction: 'hide',
		    closeable: true,
		    iconCls: 'modalWin',
		    buttonAlign: 'center',
		    buttons: [
		        {text: '导入',handler: function() { impSubmit(); }},
		        {text: '关闭', handler: function() { impWin.close(); }}
		    ]
		});

		function impSubmit(){
		    uploadForm.getForm().submit({
		        url: '<%=basePath%>internalTradeBase/internalTrade',
		        success: function(form, action) {
		        	Ext.Msg.alert("提示","导入成功！");
		        	store.load();  
		        	 impWin.close();
		        },
			failure: function(form, action){  
				Ext.Msg.alert("提示","导入失败！");
		    	store.load();  
		      }  
		    });
		}

		function toImport(){
		    impWin.show();
		}
});
</script>
</html>